<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="Bookmark" href="/favicon.ico">
    <link rel="Shortcut Icon" href="/favicon.ico"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5shiv.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>待确认订单列表</title>
</head>
<style>
    .table > tbody > tr > td {
        text-align: center;
    }
</style>
<body>

<div>
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 订单管理 <span
            class="c-gray en">&gt;</span> 微信订单列表 <a class="btn btn-success radius r"
                                                  style="line-height:1.6em;margin-top:3px"
                                                  href="javascript:location.replace(location.href);" title="刷新"><i
            class="Hui-iconfont">&#xe68f;</i></a></nav>
    <form class="page-container">
            <div class="panel panel-default  mt-20">
                <div class="panel-header">时间筛选</div>
                <div class="panel-body">
                    <div class="skin-minimal" id="time-selector">
                        <div class="check-box">
                            <input type="radio" name="time" value="0">
                            <label>所有</label>
                        </div>
                        <div class="check-box">
                            <input type="radio" name="time" value="1" checked>
                            <label>当天</label>
                        </div>
                    </div>
                </div>
            </div>
        <div class="mt-20">
            <div class="mt-20" style="margin-bottom: 70px">
                <table class="table table-border table-bordered table-bg table-hover table-sort" width="100%">
                    <thead>
                    <tr class="text-c">
                        <th width="25"><input type="checkbox" name="" value=""></th>
                        <th width="40">ID</th>
                        <th width="140">订单内容</th>
                        <th width="80">下单人</th>
                        <th width="60">订单状态</th>
                        <th width="60">下单时间</th>
                        <th width="120">操作</th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
    </form>
</div>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="lib/datatables/dataTables.colReorder.min.js"></script>
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="lib/common.js"></script>

<script type="text/javascript" src="lib/addressParse/arealist.js"></script>
<script type="text/javascript" src="lib/addressParse/address-parse.js"></script>

<script type="text/javascript">
    parseArea(areaList);


    var start = getTodayStart()
    var end = getTodayEnd()

    for (var i = 1;i<5;i++){
        var t = Date.parse(getTodayStart().replace(/-/g, "/"))
        t = t + i*24*60*60*1000
        $('#time-selector').append("<div class=\"check-box\"><input type=\"radio\" name=\"time\" value="+(parseInt(i)+1)+" ><label>"+dateymd(t)+"</label></div>")
    }



    $('input[name=state],input[name=time]').change(function (e) {

        radioValue = $('input[name=time]:checked').val()
        switch (radioValue) {
            case '1':
                start = getTodayStart()
                end = getTodayEnd()
                break
            case '0':
                start = ""
                end = ""
                break;
            default :
                console.log(radioValue)
                var t = Date.parse(getTodayStart().replace(/-/g, "/"))
                t = t + (radioValue-1)*24*60*60*1000
                start = dateAll(t)
                var e = Date.parse(getTodayEnd().replace(/-/g, "/"))
                e = e + (radioValue-1)*24*60*60*1000
                end = dateAll(e)
                break;
        }

        table.destroy()
        table =   $('.table').DataTable({
            serverSide: true,//开启服务器模式
            "processing": true,//加载显示提示
            "ajax": {
                url: "./order/wx/list",
                type: 'GET',
                data: {
                    "searchKey": "",
                    "minDate": start,
                    "maxDate":end,
                }
            },
            "columns": [
                {
                    "data": null,
                    render: function (data, type, row, meta) {
                        return "<input name=\"checkbox\" value=\"" + row.id + "\" type=\"checkbox\" value=\"\">";
                    }
                },
                {"data": "id"},
                {
                    "data": "orderContent"
                },
                {
                    "data": "memberName"
                },
                {
                    "data": "state",
                    render: function (data, type, row, meta) {
                        if (data == -1) {
                            return "<span class=\"label label-danger radius td-status\">已取消</span>";
                        } else
                        if (data == 0) {
                            return "<span class=\"label label-defant radius td-status\">未生成订单</span>";
                        } else if (data == 1) {
                            return "<span class=\"label label-success radius td-status\">已生成订单</span>";
                        }
                    }
                },
                {
                    "data": "createTime",
                    render: function (data, type, row, meta) {
                        return date(data);
                    }
                },
                {
                    "data": null,
                    render: function (data, type, row, meta) {
                        var content = row.orderContent
                        content = content.replace(/<\/?.+?>/g,"");
                        content = content.replace(/[\r\n]/g, "");
                       if (row.state == 0){
                            return '<button class="btn btn-primary radius" type="button" onclick="orderAdd(\'' + content + '\',\'' + row.id + '\',\''+row.memberId+'\',\''+row.memberName+'\')">生成订单</button>' +
                                '<button class="btn btn-danger radius" type="button" onclick="cancel(' + row.id + ')">取消订单</button>';
                        }else if(row.state ==1){
                           return '<button class="btn btn-primary radius" type="button" onclick="orderAdd(\'' +content+ '\',\'' + row.id + '\',\''+row.memberId+'\',\''+row.memberName+'\')">生成订单</button>'
                       }else {
                           return  ''
                       }
                    }
                }
            ],
            "aaSorting": [[1, "desc"]],//默认第几个排序
            "bStateSave": false,//状态保存
            "aoColumnDefs": [
                {"orderable": false, "aTargets": [0,6]}// 制定列不参与排序
            ],
            language: {
                url: './lib/datatables/Chinese.json'
            },
            colReorder: true
        });

    })



    /*datatables配置*/
     var table = $('.table').DataTable({
         serverSide: true,//开启服务器模式
         "processing": true,//加载显示提示
         "ajax": {
             url: "./order/wx/list",
             type: 'GET',
             data: {
                 "searchKey": "",
                 "minDate": start,
                 "maxDate":end,
             }
         },
         "columns": [
             {
                 "data": null,
                 render: function (data, type, row, meta) {
                     return "<input name=\"checkbox\" value=\"" + row.id + "\" type=\"checkbox\" value=\"\">";
                 }
             },
             {"data": "id"},
             {
                 "data": "orderContent"
             },
             {
                 "data": "memberName"
             },
             {
                 "data": "state",
                 render: function (data, type, row, meta) {
                     if (data == -1) {
                         return "<span class=\"label label-danger radius td-status\">已取消</span>";
                     } else
                     if (data == 0) {
                         return "<span class=\"label label-defant radius td-status\">未生成订单</span>";
                     } else if (data == 1) {
                         return "<span class=\"label label-success radius td-status\">已生成订单</span>";
                     }
                 }
             },
             {
                 "data": "createTime",
                 render: function (data, type, row, meta) {
                     return date(data);
                 }
             },
             {
                 "data": null,
                 render: function (data, type, row, meta) {
                     var content = row.orderContent
                     content = content.replace(/<\/?.+?>/g,"");
                     content = content.replace(/[\r\n]/g, "");
                     if (row.state == 0){
                         return '<button class="btn btn-primary radius" type="button" onclick="orderAdd(\'' + content + '\',\'' + row.id + '\',\''+row.memberId+'\',\''+row.memberName+'\')">生成订单</button>' +
                             '<button class="btn btn-danger radius" type="button" onclick="cancel(' + row.id + ')">取消订单</button>';
                     }else {
                         return  ''
                     }
                 }
             }
         ],
         "aaSorting": [[1, "desc"]],//默认第几个排序
         "bStateSave": false,//状态保存
         "aoColumnDefs": [
             {"orderable": false, "aTargets": [0,6]}// 制定列不参与排序
         ],
         language: {
             url: './lib/datatables/Chinese.json'
         },
         colReorder: true
     });

    function cancel(orderId) {
        layer.confirm('确认取消该订单吗？', {icon: 0}, function (index) {
            var index = layer.load(3);
            $.ajax({
                type: 'post',
                url: './order/wx/cancel',
                dataType: 'json',
                data:{
                    id:orderId
                },
                success: function (data) {
                    layer.close(index);
                    if (data.success != true) {
                        layer.alert(data.message, {title: '错误信息', icon: 2});
                        return;
                    }
                    layer.msg('取消成功!', {icon: 1, time: 1000});
                    refresh();
                },
                error: function (XMLHttpRequest) {
                    layer.close(index);
                    layer.alert('数据处理失败! 错误码:' + XMLHttpRequest.status, {title: '错误信息', icon: 2});
                }
            });
        });
    }

    var orderContent = ""
    var memberId = ""
    var memberName = ""
    var wxOrderId = ""
    var result = ""
    function orderAdd(data,woId,id,name) {

        orderContent = data
        result =  parse(data)

        memberId = id
        memberName = name
        wxOrderId = woId
        layer_show("新增订单", "order-add");
    }

    function msgSuccess(content) {
        layer.msg(content, {icon: 1, time: 3000});
    }
</script>
</body>
</html>